<?php global $ubi?>
<div class="profile">
	<div class="left ">
    	<div style="text-align:center">
    		<img src="<?php echo $ubi['SERVER']['RESOURCE_PATH'] ?>/<?php echo $resource->getResourceName()?>" class="avatar"/>
            <br />
            <?php
            	if (isset($_SESSION['userid'])) {
            		if($_SESSION['userid'] != $getVars['userid']) {
            ?>
			            <div class="user_operation">
			            	<a id="lnkSendMess" class="a_cursor">Gửi tin nhắn</a>
			            </div>
			            <?php 
			            	if (!isset($friendStatus)) {
						?>
			            <div class="user_operation">
			            	<a id="lnkMakeFriend" class="a_cursor">
			            		Kết bạn
			            	</a>
			            </div>
			            <?php
			            	} else if ($friendStatus == 0) {
			            ?>
			            <div class="user_operation">Chưa xác nhận kết bạn với bạn</div>            
			            <?php 
			            	} else if ($friendStatus == 2) {
			            ?>
			            <div class="user_operation">
			            	Đang chờ bạn xác nhận kết bạn của bạn
			            	<a class="a_cursor" onclick="$.confirmFriend('<?php echo $user->getUserID()?>', $(this))">Xác nhận</a>
			            </div>
			            <?php 		
			            	}
			            ?>
			            
			            <?php
			            	if (isset($friendStatus)) { 
			            ?>
			            <div class="user_operation"><a onclick="$.removeFriend('<?php echo $user->getUserID()?>')">Xóa khỏi danh sách</a></div>
			            <?php
			            	} 
			            ?>
			            <div class="user_operation"><a href="#">Báo cáo vi phạm</a></div>			
            <?php 
            		} else {
            ?>			
            			<div class="user_operation">
			            	<a class="a_cursor" href="index.php?view&type=avatar&userid=<?php echo $user->getUserID()?>">Cập nhật avatar</a>
			            </div>
			            <div class="user_operation">
			            	<a class="a_cursor" href="index.php?view&type=profile">Cập nhật thông tin cá nhân</a>
			            </div>
            			<div class="user_operation">
			            	<a id="lnkUserMess" class="a_cursor">
			            		Tin nhắn
			            		<?php 
				            		if ($nNewMessages > 0) {
				            			echo '<b>(' . $nNewMessages . ')</b>';
				            		}
			            		?></a>
			            </div>
			<?php			            
            		}
            	} 
            ?>                                   	
		</div>                       			                                
    </div>
    <div class="right">
    	<div class="info">
    		<h1><?php echo $user->getLastName() . ' ' . $user->getFirstName();?></h1>        	
        	<p>
                Nickname : <?php echo $user->getUserName()?><br />
                Ngày sinh : 
                	<?php 
                		echo date($ubi['SERVER']['DATE_FORMAT'],GeneralFunctions::formatDate($user->getDateOfBirth()));
                	?>
                <br />
                Giới tính : 
                <?php
            		if ($user->getGender() == 1) {
            			echo "Nam";
            		} else {
            			echo "Nữ";
            		}
            	?>
            	<br />
                Số điểm : <?php echo $user->getPoints();?> điểm <br />
                Nghề nghiệp : <?php echo $occupation->getOccupationName();?> <br />
                Món ăn yêu thích :
                <?php
                	if (count($favItemList) > 0) {
                		$item = $favItemList[0];
                ?>
                		<a href="index.php?view&type=item&id=<?php echo $item->getItemID()?>"><?php echo $item->getItem()?></a>
                <?php 
                	}               
                	                
                	for ($i = 1; $i < count($favItemList); $i++) {
                		$item = $favItemList[$i];
                ?>
                		,&nbsp;<a href="index.php?view&type=item&id=<?php echo $item->getItemID()?>"><?php echo $item->getItem()?></a>
                <?php 
                	} 
                ?> 
                <br />
                Quán ăn yêu thích :
                <?php
                	if (count($favProviderList) > 0) {
                		$provider = $favProviderList[0];
                ?>
                		<a href="index.php?view&type=provider&id=<?php echo $provider->getProviderID()?>"><?php echo $provider->getProvider()?></a>
                <?php 
                	}               
                	                
                	for ($i = 1; $i < count($favProviderList); $i++) {
                		$provider = $favProviderList[$i];
                ?>
                		,&nbsp;<a href="index.php?view&type=provider&id=<?php echo $provider->getProviderID()?>"><?php echo $provider->getProvider()?></a>
                <?php 
                	} 
                ?> 
                <br />
                <?php
                	if ($user->getMariageStatus() != null) {
                		echo $user->getMariageStatus() . '&nbsp;';
                	} 
                	if ($user->getCoupleUserName() != null) {
                ?>
                	<a href="index.php?view&type=user&username="<?php echo $user->getCoupleUserName()?>">
                <?php
                	if ($user->getCoupleNickName()) {
                		echo $user->getCoupleNickName();
                	} 
                ?>
                	</a>
                <?php 		
                	}
                ?>
                <br />  
			</p>
		</div>
	</div>
    <div style="clear:both"></div>
</div>

<div id="dlgSendMessage" title="Gửi tin nhắn">
	<form id="frmSendMess" name="frmSendMess">
		Tiêu đề<br />
		<input type="hidden" name="receiver" value="<?php echo $getVars['userid']?>" />
		<input type="text" name="title" size="44" /><br />
		Nội dung<br />		
		<textarea rows="4" cols="42" name="mess"></textarea>
		<br /><br />
		<input type="submit" value="Gửi" />
	</form>
</div>

<script language="javascript">
	$('#dlgSendMessage').dialog({autoOpen: false, width:'380px'});
	
	$('#frmSendMess').submit(function() {
		var url = "index.php?send&type=message";
		var mess = $('#frmSendMess textarea[name=mess]').val();
		var receiverId = $('#frmSendMess input[name=receiver]').val();
		var title = $('#frmSendMess input[name=title]').val();		
		
		if (receiverId && $.trim(mess) != '') {
			$.post(url, {receiverId:receiverId, mess:mess, title:title}, function(data){
				if (data) {
					$('#frmSendMess textarea[name=mess]').val('');
					$('#frmSendMess input[name=title]').val('');
					$('#dlgSendMessage').dialog('close');	
				} 
				return false;
			});
		}
		return false;
	});
	
	$('#lnkSendMess').click(function() {
		$('#dlgSendMessage').dialog('open');							
	});

	$('#lnkUserMess').click(function() {
		$('#userMessage').show();
		$('#userMessage').load("index.php?message&type=allMessages");
	});

	$('#lnkMakeFriend').click(function() {
		var userid = <?php echo $user->getUserID()?>;
		var url = "index.php?add&type=friend&userid=" + userid;
		
		$.post(url, function(data) {
			alert('Gửi tin nhắn kết bạn thành công');
		});
	});
</script>